package edu.gatech.ealf.secretservantplaf;

import java.util.HashMap;
import java.util.Map;

import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;

import edu.gatech.ealf.AuxiliaryUIDefaults;

public class SecretServantLookAndFeel extends LookAndFeel {

	private UIDefaults uidefaults = null;
    
	private static SecretServantLookAndFeel instance = null;
    
	private Map<JComponent, String> activeComponentIndex = new HashMap<JComponent, String>(100);
	
    public static SecretServantLookAndFeel getInstance(){
    	if(instance == null){
    		instance = new SecretServantLookAndFeel();
    	}
    	return instance;
    }
    
	private SecretServantLookAndFeel(){

		uidefaults = new AuxiliaryUIDefaults();
        Object[] uiDefaults = {
        		"MenuBarUI", "edu.gatech.ealf.secretservantplaf.SSMenuBarUI",
        		"ToggleButtonUI", "edu.gatech.ealf.secretservantplaf.SSToggleButtonUI",
        		"CheckBoxUI", "edu.gatech.ealf.secretservantplaf.SSCheckBoxUI",
        		"ColorChooserUI", "edu.gatech.ealf.secretservantplaf.SSColorChooserUI",
        		"RootPaneUI", "edu.gatech.ealf.secretservantplaf.SSRootPaneUI",
        		"SplitPaneUI", "edu.gatech.ealf.secretservantplaf.SSSplitPaneUI",
        		"TextFieldUI", "edu.gatech.ealf.secretservantplaf.SSTextFieldUI",
        		"TableUI", "edu.gatech.ealf.secretservantplaf.SSTableUI",
        		"ViewportUI", "edu.gatech.ealf.secretservantplaf.SSViewportUI",
        		"ButtonUI", "edu.gatech.ealf.secretservantplaf.SSButtonUI",
        		"FileChooserUI", "edu.gatech.ealf.secretservantplaf.SSFileChooserUI",
        		"RadioButtonMenuItemUI", "edu.gatech.ealf.secretservantplaf.SSRadioButtonMenuItemUI",
        		"DesktopIconUI", "edu.gatech.ealf.secretservantplaf.SSDesktopIconUI",
        		"FormattedTextFieldUI", "edu.gatech.ealf.secretservantplaf.SSFormattedTextFieldUI",
        		"ProgressBarUI", "edu.gatech.ealf.secretservantplaf.SSProgressBarUI",
        		"EditorPaneUI", "edu.gatech.ealf.secretservantplaf.SSEditorPaneUI",
        		"TabbedPaneUI", "edu.gatech.ealf.secretservantplaf.SSTabbedPaneUI",
        		"ToolTipUI", "edu.gatech.ealf.secretservantplaf.SSToolTipUI",
        		"TableHeaderUI", "edu.gatech.ealf.secretservantplaf.SSTableHeaderUI",
        		"PopupMenuUI", "edu.gatech.ealf.secretservantplaf.SSPopupMenuUI",
        		"OptionPaneUI", "edu.gatech.ealf.secretservantplaf.SSOptionPaneUI",
        		"MenuUI", "edu.gatech.ealf.secretservantplaf.SSMenuUI",
        		"ScrollBarUI", "edu.gatech.ealf.secretservantplaf.SSScrollBarUI",
        		"DesktopPaneUI", "edu.gatech.ealf.secretservantplaf.SSDesktopPaneUI",
        		"MenuItemUI", "edu.gatech.ealf.secretservantplaf.SSMenuItemUI",
        		"ToolBarUI", "edu.gatech.ealf.secretservantplaf.SSToolBarUI",
        		"ComboBoxUI", "edu.gatech.ealf.secretservantplaf.SSComboBoxUI",
        		"PasswordFieldUI", "edu.gatech.ealf.secretservantplaf.SSPasswordFieldUI",
        		"SpinnerUI", "edu.gatech.ealf.secretservantplaf.SSSpinnerUI",
        		"InternalFrameUI", "edu.gatech.ealf.secretservantplaf.SSInternalFrameUI",
        		"CheckBoxMenuItemUI", "edu.gatech.ealf.secretservantplaf.SSCheckBoxMenuItemUI",
        		"ToolBarSeparatorUI", "edu.gatech.ealf.secretservantplaf.SSToolBarSeparatorUI",
        		"ScrollPaneUI", "edu.gatech.ealf.secretservantplaf.SSScrollPaneUI",
        		"PopupMenuSeparatorUI", "edu.gatech.ealf.secretservantplaf.SSPopupMenuSeparatorUI",
        		"PanelUI", "edu.gatech.ealf.secretservantplaf.SSPanelUI",
        		"SeparatorUI", "edu.gatech.ealf.secretservantplaf.SSSeparatorUI",
        		"TextAreaUI", "edu.gatech.ealf.secretservantplaf.SSTextAreaUI",
        		"LabelUI", "edu.gatech.ealf.secretservantplaf.SSLabelUI",
        		"TreeUI", "edu.gatech.ealf.secretservantplaf.SSTreeUI",
        		"RadioButtonUI", "edu.gatech.ealf.secretservantplaf.SSRadioButtonUI",
        		"ListUI", "edu.gatech.ealf.secretservantplaf.SSListUI",
        		"TextPaneUI", "edu.gatech.ealf.secretservantplaf.SSTextPaneUI",
        		"SliderUI", "edu.gatech.ealf.secretservantplaf.SSSliderUI"
        };
        uidefaults.putDefaults(uiDefaults);
        

	}
	
	@Override
	public String getDescription() {
		return "A Look and Feel that just watches things";
	}

	@Override
	public String getID() {
		return "SecretServantLookAndFeel";
	}

	@Override
	public String getName() {
		return "SecretServantLookAndFeel";
	}

	@Override
	public boolean isNativeLookAndFeel() {
		return false;
	}

	@Override
	public boolean isSupportedLookAndFeel() {
		return true;
	}
	
	@Override
	public UIDefaults getDefaults() {
        return uidefaults;
    }
	
	public void registerComponentInstallation(String uiName, JComponent component){
		//System.out.print("InstallComponent: " + uiName + " " + component.getName());
		activeComponentIndex.put(component, uiName);
        //System.out.println(" " + activeComponentIndex.size());
	}
	
	public void registerComponentUninstallation(String uiName, JComponent component){
		//System.out.print("UninstallComponent: " + uiName + " " + component.getName());
		activeComponentIndex.remove(component);
        //System.out.println(" " + activeComponentIndex.size());
	}
    
    public Map<JComponent, String> getActiveComponentIndex(){
        return activeComponentIndex;
    }
	

}
